﻿@model DayWin
<div class="main">
    @*@Html.Action("Banner")
    @Html.Action("Scroll")*@
    <div class="strdeprocess">
        <div class="line"></div>
        <ul>
            <li>
                <i>1</i>
                <span>申请操盘资金</span>
            </li>
            <li>
                <i class="cur">2</i>
                <span>支付保证金</span>
            </li>
            <li>
                <i>3</i>
                <span>操盘申请成功</span>
            </li>
            <li>
                <i>4</i>
                <span>开始投资股票</span>
            </li>
            <li class="last">
                <i>5</i>
                <span>盈利全归您</span>
            </li>

        </ul>
    </div>
    <div class="traderbox">
        <div class="content confirm">
            <div class="t">支付风险保证金</div>
            <div class="c">
                <p>
                    支付风险保证金 <em>@ViewBag.RiskMargin</em>元 + 预存
                    <select id="ManageDay">
                        <option value="2">2天</option>
                        <option value="3">3天</option>
                        <option value="4">4天</option>
                        <option value="5" selected="selected">5天</option>
                        <option value="6">6天</option>
                        <option value="7">7天</option>
                        <option value="10">10天</option>
                        <option value="15">15天</option>
                        <option value="20">20天</option>
                        <option value="30">30天</option>
                    </select>
                    <input type="hidden" value="@Model.ManageMoney" id="ManageMoney" />
                    账户管理费 <em id="ManageMoneyTotal">@(Model.ManageMoney * 5)</em>元
                </p>
                <p>预存的账户管理费会先存入到您的账户，<span>使用一天扣一天</span>。如账户余额充足，<span>默认每天自动延期</span>，扣除当天管理费，否则自动终止。
                </p>

            </div>
            
                @if (ViewBag.BalanceAmount != null)
                {
                    decimal a = (ViewBag.RiskMargin + Model.ManageMoney*5) - ViewBag.BalanceAmount;
                    <div class="ac" id="BalanceAmount">
                        @if (a <= 0)
                        {
                            <span>您的账户余额：@(ViewBag.BalanceAmount)元</span>
                        }
                        else
                        {
                            <span>您的账户余额只剩@(ViewBag.BalanceAmount)元，本次支付还差@(a)元，<a class="blue" target="_blank" href='@Url.DomainRouteUrl(AreasConfig.Web, new { controller = "pay", action = "index", id = (ViewBag.CurentUser!=null?ViewBag.CurentUser.UserId:0) })'>马上充值</a></span>
                        }
                    </div>
                }
                else
                {
                    <div class="ac" id="BalanceAmount"></div>

                }
            

            <p>
                <input type="button" id="DetermineBtn" class="button red" value="确定操盘" />
                <input type="button" class="button grey" id="BackUpdate" value="返回修改" style="margin-left: 10px;" />
            </p>
            <div class="left">
                <div class="firminput">
                    <p class="i"><em>@Model.FirmCapital</em>元
                    </p>
                    <p>实盘资金</p>
                </div>
            </div>
            <div class="right">
                <ul>
                    <li>
                        <b>操盘须知</b>
                        <span style="line-height: 25px;">@Html.Raw(MathProject.GetLismit(Model.FirmCapital,Model.RiskMargin))</span>
                    </li>
                    <li>
                        <b>风险保证金</b>
                        <span>
                            <em>@ViewBag.RiskMargin</em>元
                        </span>
                    </li>
                    <li>
                        <b>总操盘资金</b>
                        <span><em>@Model.TotalTrade.MoneyFormat()</em>元</span>
                    </li>
                    <li>
                        <b>亏损警戒线</b>
                        <span><em>@Model.LossWarLine.MoneyFormat()</em>元</span>
                    </li>
                    <li>
                        <b>亏损平仓线</b>
                        <span><em style="color: #cd1818">@Model.LossOpenLine.MoneyFormat()</em>元</span>
                    </li>
                    <li>
                        <b>资金使用期限</b>
                        <span><i>2</i>天-<i>30</i>天</span>
                    </li>
                    <li>
                        <b>账户管理费</b>
                        <span><i >@Model.ManageMoney</i>元 / 每天<i class="red">按天收取，周末节假日免费</i></span>

                    </li>
                    <li>
                        <b>开始交易时间</b>
                        <span>@(Model.StartTime == 0 ? "今天" : "下个交易日")</span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    @{Html.RenderPartial("Info");}
</div>
<script type="text/javascript">
    $(function() {

        $("#ManageDay").bind("change", function() {
            var $this = $(this);
            var manageMoney = parseInt($("#ManageMoney").val());
            var totalManageMoney = manageMoney * $this.val();
            $("#ManageMoneyTotal").html(totalManageMoney);
            if ($.isLogin()) {
                var a = @ViewBag.RiskMargin + totalManageMoney - @(ViewBag.BalanceAmount ?? 0);
                if (a <= 0) {
                    $("#BalanceAmount").html("<span>您的账户余额：" + @ViewBag.BalanceAmount + "元</span>");
                } else {
                    $("#BalanceAmount").html("<span>您的账户余额只剩" + @ViewBag.BalanceAmount + "元，本次支付还差"+a+"元，<a href='@Url.DomainRouteUrl(AreasConfig.Web, new { controller = "pay", action = "index", id = (ViewBag.CurentUser!=null?ViewBag.CurentUser.UserId:0) })'>马上充值</a></span>");
                }
            }
        });

        $("#BackUpdate").bind("click", function() {
            window.location.href = "@Url.DomainRouteUrl(AreasConfig.Web, new { controller = "daywin", action = "index", param = string.Format("FirmCapital={0}&RiskMargin={1}&TotalTrade={2}&LossWarLine={3}&LossOpenLine={4}&ManageMoney={5}&StartTime={6}&IsFree={7}&Type={8}", Model.FirmCapital, Model.RiskMargin, Model.TotalTrade, Model.LossWarLine, Model.LossOpenLine, Model.ManageMoney, Model.StartTime, Model.IsFree,Model.Type) })";
        });

        var postProject = function() {
            $.jajax({
                url: "@Url.DomainRouteUrl(AreasConfig.Web, "PostConfirm", "DayWin")",
                params: {
                    FirmCapital: "@Model.FirmCapital",
                    RiskMargin: "@Model.RiskMargin",
                    TotalTrade: "@Model.TotalTrade",
                    LossWarLine: "@Model.LossWarLine",
                    LossOpenLine: "@Model.LossOpenLine",
                    ManageMoney: "@Model.ManageMoney",
                    StartTime: "@Model.StartTime",
                    FundTime: $("#ManageDay").val(),
                    IsFree: "@Model.IsFree"
                },
                callback: function(ret) {
                    if (!ret) {
                        return;
                    }
                    if (ret.data == 3) { //账户余额不足
                        $.StockWindow({
                            title: "账户余额不足",
                            id: "PostProject-Window",
                            classes: "project",
                            content: '<label>您的账户余额不足，请先充值</label><label><a target="_blank" class="button recharge" href="@Url.DomainRouteUrl(AreasConfig.Web, new {controller = "pay", action = "index", id = (ViewBag.CurentUser != null ? ViewBag.CurentUser.UserId : 0)})">立即充值</a><a class="button recharge un" href="javascript:$(\'#PostProject-Window\').CloseWindow()">暂不充值</a></label>'
                        });
                    }
                    if (ret.message == "ok" && ret.data>0) {
                        window.location.href = "/daywin/seccess/" + ret.data;
                    }
                }
            });
        };
        //确定操盘
        $("#DetermineBtn").bind("click", function() {
            if (!$.isLogin()) {
                login.load(function() {
                    postProject();
                });
            } else {
                postProject();
            }
        });

    });
</script>